package com.example.library_common.view.inner_shadow;

import android.content.Context;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.RadialGradient;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

public class InnerShadowLinearLayout extends LinearLayout {

    private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

    private RectF rect = new RectF();

    public InnerShadowLinearLayout(Context context) {
        this(context,null);
    }

    public InnerShadowLinearLayout(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public InnerShadowLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        //关闭硬件加速
        setLayerType(View.LAYER_TYPE_SOFTWARE,null);
        paint.setColor(Color.RED);
        paint.setStyle(Paint.Style.FILL);
        paint.setStrokeWidth(10);
//        Shader mShader = new RadialGradient(0.5f, 0.5f, 10,new int[] { Color.RED, Color.GREEN}, null, Shader.TileMode.REPEAT);
        paint.setMaskFilter(new BlurMaskFilter(100, BlurMaskFilter.Blur.INNER));
//        paint.setShadowLayer(10,-4,-4,Color.RED);

//        paint.setShader(mShader);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);
        rect.left=0;
        rect.right=getWidth();
        rect.top=0;
        rect.bottom=getHeight();
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);
//        rect.left=getLeft();
//        rect.right=getRight();
//        rect.top=getTop();
//        rect.bottom=getBottom();
        canvas.drawRoundRect(rect,4,4,paint);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

    }
}
